package com.ruoyi.appraise.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.filter.ID;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.appraise.domain.AtbAppraise;
import com.ruoyi.appraise.service.IAtbAppraiseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 买房估价Controller
 * 
 * @author ruoyi
 * @date 2024-09-16
 */
@RestController
@RequestMapping("/appraise/appraise")
public class AtbAppraiseController extends BaseController
{
    @Autowired
    private IAtbAppraiseService atbAppraiseService;

    /**
     * 查询买房估价列表
     */
    @PreAuthorize("@ss.hasPermi('appraise:appraise:list')")
    @GetMapping("/list")
    public TableDataInfo list(AtbAppraise atbAppraise)
    {
        startPage();
        List<AtbAppraise> list = atbAppraiseService.selectAtbAppraiseList(atbAppraise);
        return getDataTable(list);
    }

    /**
     * 导出买房估价列表
     */
    @PreAuthorize("@ss.hasPermi('appraise:appraise:export')")
    @Log(title = "买房估价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AtbAppraise atbAppraise)
    {
        List<AtbAppraise> list = atbAppraiseService.selectAtbAppraiseList(atbAppraise);
        ExcelUtil<AtbAppraise> util = new ExcelUtil<AtbAppraise>(AtbAppraise.class);
        util.exportExcel(response, list, "买房估价数据");
    }

    /**
     * 获取买房估价详细信息
     */
    @PreAuthorize("@ss.hasPermi('appraise:appraise:query')")
    @GetMapping(value = "/{appraiseId}")
    public AjaxResult getInfo(@PathVariable("appraiseId") Long appraiseId)
    {
        AtbAppraise atbAppraise = atbAppraiseService.selectAtbAppraiseByAppraiseId(appraiseId);
        return AjaxResult.success(atbAppraise);
    }

    /**
     * 新增买房估价
     */
    @PreAuthorize("@ss.hasPermi('appraise:appraise:add')")
    @Log(title = "买房估价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AtbAppraise atbAppraise, @RequestHeader(value = "Authorization") String token)
    {
        ID id = new ID();
        //后端管理没有添加功能,前端到时候根据用户id添加

        atbAppraise.setAppraiseId(id.getId());
        return toAjax(atbAppraiseService.insertAtbAppraise(atbAppraise));
    }

    /**
     * 修改买房估价
     */
    @PreAuthorize("@ss.hasPermi('appraise:appraise:edit')")
    @Log(title = "买房估价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AtbAppraise atbAppraise)
    {
        return toAjax(atbAppraiseService.updateAtbAppraise(atbAppraise));
    }

    /**
     * 删除买房估价
     */
    @PreAuthorize("@ss.hasPermi('appraise:appraise:remove')")
    @Log(title = "买房估价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appraiseIds}")
    public AjaxResult remove(@PathVariable Long[] appraiseIds)
    {
        return toAjax(atbAppraiseService.deleteAtbAppraiseByAppraiseIds(appraiseIds));
    }
}
